package ma.model.auxillary;

import java.util.List;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public abstract class ParameterCollection {
		
	private String name;	
	protected List<Parameter> parameters;	
	private int keyNumber;
	private int parametersCount;
		
	public ParameterCollection(String name) {
		this.name = name;
		parameters = new ArrayList<Parameter>();
		keyNumber = 0;
		parametersCount = 0;
		addParameters();
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public List<Parameter> getParameters() {
		return parameters;
	}
	
	public void addParameter(Parameter param) {
		parameters.add(param);
		parametersCount++;
	}
	
	public void removeParameter(Parameter param) {
		if (parameters.contains(param)) {
			parameters.remove(param);
			parametersCount--;
		} else {
			throw new NoSuchElementException(
					this + " does not hold " + param);
		}		
	}
	
	public void setParameter(String parameterAbbreviation, double value) {
		getParameter(parameterAbbreviation).setValue(value);
	}
	
	public Parameter getParameter(String parameterAbbreviation)
		throws NoSuchElementException {
			if(parameterAbbreviation != null) {
				for (Parameter param : parameters) {
					if(param.getAbbreviation() == parameterAbbreviation){	                                                            
	                    return param;
	                }
				}
			}		
			throw new NoSuchElementException(
					"'" + parameterAbbreviation + "' not found in " 
							+ name + "!");
	}
	
	public int getKey() {
		return keyNumber++;
	}
	
	public int getParamCount() {
		return parametersCount;
	}
	
	/**
	 * To add parameters to this collection.
	 */
	protected abstract void addParameters();
}
